<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Secretly</title>
</head>
<body>

<div class="container">
    <div class="form-control">
        <textarea id="content" placeholder="input something.."></textarea>
    </div>
    <div class="form-control">
        <button onclick="decode()">解码</button>
        <button onclick="encode()">编码</button>
    </div>
</div>

</body>

<script language="javascript">

    let dom, d = document;
    d.addEventListener('DOMContentLoaded', function(){
        dom = d.getElementById('content');
    });
    
    function decode() {
        let content = [], arr = dom.value.split('\n');
        for(let i = 0; i < arr.length; i ++){
            content.push(String.fromCharCode(parseInt(arr[i], 2)));
        }
        dom.value = content.join('');
    }

    function encode() {
        let content = [];
        for(let i = 0; i < dom.value.length; i ++){
            content.push(dom.value.charCodeAt(i).toString(2));
        }
        dom.value = content.join('\n');
    }

</script>

</html>